package com.dnuifoodqgx618.dnuifood_16110100618.model;

import android.provider.SyncStateContract;

import com.dnuifoodqgx618.dnuifood_16110100618.bean.ResultBean;
import com.dnuifoodqgx618.dnuifood_16110100618.bean.UserBean;
import com.dnuifoodqgx618.dnuifood_16110100618.iterface.UserIface;
import com.dnuifoodqgx618.dnuifood_16110100618.listener.OnRetrofitListener;
import com.dnuifoodqgx618.dnuifood_16110100618.service.UserService;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserModel extends RetrofitBaseModel implements UserIface {
    private UserService userService;
    public UserModel(){
        this.userService=retrofit.create(UserService.class);
    }

    @Override
    public void login(String username, String userpass, OnRetrofitListener listener) {
        Call call = userService.userLogin(username,userpass);
        bindCallback(call,listener,Constant.USERLOGIN);
    }

    @Override
    public void register(String username, String userpass, String mobilenum, String address, String comment, OnRetrofitListener listener) {
        Call call = userService.doregister(username,userpass,mobilenum,address,comment);
        bindCallback(call,listener,Constant.USEREGISTER);
    }
//    public Retrofit retrofit;
//    public UserService service;
//    public final static String Baseurl="http://172.24.10.175:8080/foodService/";
//    public UserModel(){
//        retrofit = new Retrofit.Builder().baseUrl(Baseurl).addConverterFactory(GsonConverterFactory.create()).build();
//        this.service=retrofit.create(UserService.class);
//    }
//    public void login(String username, String userpass, final OnRetrofitListener listener) {
//        retrofit = new Retrofit.Builder().baseUrl(Baseurl).addConverterFactory(GsonConverterFactory.create()).build();
//        UserService userService = retrofit.create(UserService.class);
//        Call<UserBean> call = userService.userLogin(username,userpass);
//        call.enqueue(new Callback<UserBean>() { //加入到异步线程
//            @Override
//            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
//                    if (response.body()!=null)
//                        listener.onsuccess(response.body(),1);
//                    else
//                        listener.onFailure("解析有误");
//            }
//
//            @Override
//            public void onFailure(Call<UserBean> call, Throwable t) {
//                    listener.onFailure("联网异常！");
//            }
//        });
//    }
//
//    @Override
//    public void register(String username, String userpass, String mobilenum, String address, String comment, final OnRetrofitListener listener) {
//        retrofit = new Retrofit.Builder().baseUrl(Baseurl).addConverterFactory(GsonConverterFactory.create()).build();
//        UserService userService = retrofit.create(UserService.class);
//        Call<UserBean> call = userService.doregister(username,userpass,mobilenum,address,comment);
//        call.enqueue(new Callback<UserBean>() { //加入到异步线程
//            @Override
//            public void onResponse(Call<UserBean> call, Response<UserBean> response) {
//                if (response.body()!=null)
//                    listener.onsuccess(response.body(),2);
//                else
//                    listener.onFailure("解析有误");
//            }
//
//            @Override
//            public void onFailure(Call<UserBean> call, Throwable t) {
//                listener.onFailure("联网异常！");
//            }
//        });
//    }



}

